package com.itheima.api.collection.demo01;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.function.Consumer;

public class CollectionDemo01 {

    public static void main(String[] args) {

        Collection<String> collection = new ArrayList<String>();
        collection.add("蓝忘机");
        collection.add("魏无羡");

        Iterator<String> iterator = collection.iterator();
        while (iterator.hasNext()){
            System.out.println(iterator.next());
        }
        System.out.println("------------------");

        for (String s : collection){
            System.out.println(s);
        }
        System.out.println("------------------");

        collection.forEach(new Consumer<String>() {
            @Override
            public void accept(String s) {
                System.out.println(s);
            }
        });
        System.out.println("------------------");

        collection.forEach((String s) -> {
            System.out.println(s);
        });
        System.out.println("------------------");
    }
}
